package cn.com.eliteUtil;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

public class MeiLian {
	public String getresult(String a) throws Exception{
		Document doc;
		DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
		dbf.setNamespaceAware(true);
		DocumentBuilder db = dbf.newDocumentBuilder();
		InputStream is = String2InputStream(a);
		doc = db.parse(is);
//		NodeList nl = doc.getElementsByTagName("CreateAndUpdateCustomerResult");
		NodeList nl = doc.getElementsByTagName("Lead_leadid");
		StringBuffer sb = new StringBuffer();
		for (int count = 0; count < nl.getLength(); count++){
			Node n = nl.item(count);
			sb.append(n.getFirstChild().getNodeValue());
		}
		is.close();	   
		return sb.toString();  
	}
	 public static InputStream String2InputStream(String str){
		 ByteArrayInputStream stream = new ByteArrayInputStream(str.getBytes());
		   return stream;
	 }
	 public static void main(String[] args){
		 String a="<?xml version='1.0' encoding='utf-8'?>" +
		 		"<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'><soap:Body>" +
		 		"<PersAndLeadAndCommNewOrEditResponse xmlns='http://127.0.0.1/'><PersAndLeadAndCommNewOrEditResult><Lead_leadid>0</Lead_leadid><Pers_personid>0</Pers_personid><Res>-5</Res><Message>CRM提供的程序出错了！</Message></PersAndLeadAndCommNewOrEditResult></PersAndLeadAndCommNewOrEditResponse></soap:Body></soap:Envelope>";
		 a=a.replace("utf-8","gb2312");
		 try {
	    	 MeiLian meiLian=new MeiLian();
			System.out.println("a:"+meiLian.getresult(a));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	 }
		
}
